package 我的Java学习_算法基础.day_02;

public class _016_汉诺塔 {
    public static void main(String[] args) {
        printHanoiTower(3,"A","C","B");
    }

    /**
     * 将N个盘子从source移动到target的路径的打印
     * @param n 初始的N个从小到大的盘子，N是最大编号
     * @param from 原始柱子
     * @param to 辅助柱子
     * @param help 目标的柱子
     */
    static void printHanoiTower(int n,String from,String to,String help){
        if(n == 1){
            System.out.println("move " + n + " from "+ from + " to " + to);
            return;
        }
        printHanoiTower(n-1, from, help, to);
        System.out.println("move " + n + " from "+ from + " to " + to);
        printHanoiTower(n-1, help, to, from);
    }
}
/*
static void printHanoiTower(int N,String from,String to,String help){
        if(N==1){
            System.out.println("move "+N+" from "+from+" to "+to);
            return;
        }
        printHanoiTower(N-1,from,help,to);      //先把前N-1个盘子挪到辅助空间上去
        System.out.println("move "+N+" from "+from+" to "+to);  //N可以顺利到达target
        printHanoiTower(N-1,help,to,from);  //让N-1从辅助空间到目标空间
    }
 */


